import os,sys
import settings
from readAndWriteID3 import readAndWriteID3

class fileScanner():

    def __init__(self):
        self.filetypes = (".mp3",".ogg")
        self.files = []
        self.scanned = False
        self.OldDirectory=""

    def scan2( self, directory=""):
        path="."
        #si no se pasa un parametro con el dir a mirar mira es del script
        if directory==self.OldDirectory:
            self.scanned = False
        else:
            self.scanned = True

        if directory!="":
            path = directory
        if self.scanned:
            os.path.walk(path,self.walker,None)
        #aqui ya tendriamos la lista files llena
        self.scanned = True
        self.OldDirectory = directory;
        #print self.files
    def scan( self, directory=""):
        path="."
        #si no se pasa un parametro con el dir a mirar mira es del script
        if directory!="":
            path = directory
        os.path.walk(path,self.walker,None)
        #aqui ya tendriamos la lista files llena
        self.scanned = True
        self.OldDirectory = directory;
        #print self.files

    def walker(self, arg,dirname,names):
        names=filter(lambda x: x.lower().endswith((".mp3",".ogg")),names)
        # linea informando de los ficheros que hay 
        #print dirname , len(names),"files"
        #relative path
        for i in xrange(len(names)):
            names[i]=dirname+'/'+names[i]
        self.files = self.files + names

    def getFiles(self):
        return self.files

    def getTotal(self):
        return len(self.files)
    
    def checkTotal(self):
        newSong = song("/folder","macarena","1los rodriguez")
        myThread.startSGAEProcess( newSong )
        myThread.endSGAEFinishProcess()



#f = fileScanner()
#f.scan(".")